package com.base.cn.platform.os.controller.manage.help;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.manage.help.SysHelpCenter;
import com.base.cn.platform.os.service.manage.help.SysHelpCenterBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 帮助中心Controller
 *
 * @author s.li
 * @create 2018-03-26 18:53
 */
@RestController
@RequestMapping("/manage")
public class SysHelpCenterController extends BaseController {

    @Autowired
    private SysHelpCenterBiz sysHelpCenterBiz;

    /**
     * 保存帮助文档
     * @param helpCenter 帮助文档对象
     * @return Map<String,Object>
     */
    @RequestMapping("/saveHelpCenter")
    public Map<String,Object> saveHelpCenter(@RequestBody SysHelpCenter helpCenter){
        if(StringUtils.isEmpty(helpCenter.getHelpName())){
            return ResultUtil.ERROR("帮助文档名不能为空");
        }
        if(helpCenter.getHelpName().trim().length()>30){
            return ResultUtil.ERROR("帮助文档名称限制在30个字以内");
        }
        return ResultUtil.SUCCESS("帮助文档保存成功", sysHelpCenterBiz.saveSysHelpCenter(helpCenter));
    }

    /**
     * 查询帮助文档列表
     * @param sysHelpCenter 查询条件
     * @param contextData 是否获取内容，true获取，false不获取
     * @return List<SysHelpCenter>
     */
    @RequestMapping("/findSysHelpCenter")
    public List<SysHelpCenter> findSysHelpCenter(@RequestBody SysHelpCenter sysHelpCenter,
                                                 @RequestParam("contextData") boolean contextData){
        return sysHelpCenterBiz.findSysHelpCenter(sysHelpCenter,contextData);
    }

    /**
     * 通过ID查询帮助文档内容
     * @param helpId 帮助ID
     * @return SysHelpCenter
     */
    @RequestMapping("/findHelpCenterById")
    public SysHelpCenter findHelpCenterById(@RequestParam("id") BigDecimal helpId){
        return sysHelpCenterBiz.findById(helpId);
    }

    /**
     * 删除帮助文档数据
     * @param ids 帮助文档ID串
     * @return Map<String,Object>
     */
    @RequestMapping("/deleteHelpCenter")
    public Map<String,Object> deleteHelpCenter(@RequestParam("ids") String ids){
        sysHelpCenterBiz.deleteSysHelpCenter(ids);
        return ResultUtil.SUCCESS("帮助文档删除成功");
    }

    /**
     * 修改帮助状态成功
     * @param ids 状态ID串
     * @param status 状态，1正常，2隐藏
     * @return Map<String,Object>
     */
    @RequestMapping("/updateHelpStatus")
    public Map<String,Object> updateHelpStatus(@RequestParam("ids") String ids,@RequestParam("status") int status){
        sysHelpCenterBiz.updateHelpStatus(ids,status);
        return ResultUtil.SUCCESS("帮助文档状态修改");
    }

    /**
     * 获取前台底部帮助文档数据
     * @return List<SysHelpCenter>
     */
    @RequestMapping("/findWebFooterHelp")
    public List<SysHelpCenter> findWebFooterHelp(){
        SysHelpCenter center = new SysHelpCenter();
        center.setShowClients(2);
        center.setFrontBottom(1);
        center.setStatus(1);
        return sysHelpCenterBiz.findWebFooterHelp(center);
    }

    /**
     * 获取帮助中心内容
     * @param helpCenter
     * @return
     */
    @RequestMapping("/findPageHelpList")
    public List<SysHelpCenter> findPageHelpList(@RequestBody SysHelpCenter helpCenter,@RequestParam("contextData") boolean contextData){
        return sysHelpCenterBiz.findLayeredPageHelpList(helpCenter , contextData);
    }
}
